<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="../common/jspcommon.jsp"%>
<%@include file="../common/jscss.jsp"%>
<script type="text/javascript">
	var userGrid = null;
	var editUserDialog = null;
	$(function(){
		userGrid = $("#user_grid").ligerGrid({
				title : '用户列表',
                columns: [
                { display: '用户名', name: 'username', isSort : false, width: 120 },
                { display: '邮箱', name: 'email', isSort : false, width: 120 },
                { display: '真实姓名', name: 'realname',isSort : false, width: 200 },
                { display: '用户简介', name: 'description',isSort : false, width: 200 }, 
                { display: '创建时间', name: 'gmtCreated',isSort : false,
                  render: function(record, rowindex, value, column){
                	 return (new Date(value.time)).format("yyyy年MM月dd日 hh:mm:ss");
                  }}, 
                { display: '最后修改时间', name: 'gmtModified',isSort : false,
                  render: function(record, rowindex, value, column){
                	 return (new Date(value.time)).format("yyyy年MM月dd日 hh:mm:ss");
                  }
                },
                {
                	display: '<a href="javascript:;" onclick="addUser()">添加用户</a>', 
                	name: 'id',
                	isAllowHide: false, 
                	isSort : false,
					render: function (record, rowindex, value, column){
					//this     这里指向grid
					//record   行数据
					//rowindex 行索引
					//value    当前的值，对应record[column.name]
					//column   列信息
						var html = '<a onclick="authorize(\''+ value + '\')" href="#">授权</a>&nbsp;<a onclick="editUser(\''+ value + '\')" href="javascript:;">编辑</a>&nbsp;<a onclick="deleteUser(\''+ value + '\')" href="javascript:;">删除</a>'; 
						return html; 
					}
                }
                ], 
                pageSize:30,
                root :'list',
                record:'totalRecord',
                url: "/misc/admin/userGrid.htm", 
                width: '99%',height:'99%'
            });


	});
	
	function deleteUser(userId){
		$.ligerDialog.confirm('你真的要删除吗？', 
			function (yes){
				if(yes){
					$.post("/misc/admin/deleteUser.htm",{userId:userId},function(){
						userGrid.loadData();
					}); 
				}
			});
	}
	
	function editUser(id){
		editUserDialog = $.ligerDialog.open({ height: 300,width:500, url: "/misc/admin/editUser.htm?id="+id, isResize: false ,modal:true,title:'编辑用户'});
	}
	
	function addUser(){
		editUserDialog = $.ligerDialog.open({ height: 330,width:500, url: "/misc/admin/addUser.htm", isResize: false ,modal:true,title:'添加用户'});
	
	}
	
	function authorize(id){
		editUserDialog = $.ligerDialog.open({ height:300,width:500, url: "/misc/admin/authorize.htm?id="+id, isResize: false ,modal:true,title:'给用户分配角色'});
	}
</script>
<div id="user_grid" style="margin:0; padding:0"></div>
